<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
		body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="//api.map.baidu.com/api?v=2.0&ak=4d1f8197ee08aecbbc9ed79ca3adbeb2"></script>
	<title>武汉求助者分布图</title>
</head>
<body>
	<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
	fetch('address.txt')
	.then(response => response.text())
	.then(data => showAddress(data));
	
	// 百度地图API功能
	var map = new BMap.Map("allmap");
	var point = new BMap.Point(114,30);
	map.centerAndZoom(point,12);
	// 创建地址解析器实例
	var myGeo = new BMap.Geocoder();
	// 将地址解析结果显示在地图上,并调整地图视野
	var top_left_control = new BMap.ScaleControl({anchor: BMAP_ANCHOR_TOP_LEFT});// 左上角，添加比例尺
	var top_left_navigation = new BMap.NavigationControl();  //左上角，添加默认缩放平移控件
	var top_right_navigation = new BMap.NavigationControl({anchor: BMAP_ANCHOR_TOP_RIGHT, type: BMAP_NAVIGATION_CONTROL_SMALL}); //
	
	function showAddress(txt){
		var address = txt.split("\n")
		for(var i=0;i<address.length;i++){
		myGeo.getPoint(address[i], 
			function(addr){
				return function(point){
					addMarker(point,addr)
				}
			}(address[i]), "武汉市");
		}
		map.addControl(top_left_control);        
		map.addControl(top_left_navigation);     	
	}
	function addMarker(point,addr){
		if (point) {
			map.centerAndZoom(point, 12);
			var marker = new BMap.Marker(point,{title:addr});
			if(/showAddress/i.test(location.hash)){
				var label = new BMap.Label(addr,{offset:new BMap.Size(20,-10)});//标注标签  
	 			marker.setLabel(label)				
			}
			map.addOverlay(marker);
		}else{
			console.log("您选择地址没有解析到结果!");
		}
	}
</script>